Skip to content

perf: Migrate to Flashlist in MoneyRequestReportTransactionList#91422

Merged
mountiny merged 111 commits into
Expensify:mainfrom
callstack-internal:perf/virtualised-report-list
Jul 24, 2026
Merged

perf: Migrate to Flashlist in MoneyRequestReportTransactionList#91422
mountiny merged 111 commits into
Expensify:mainfrom
callstack-internal:perf/virtualised-report-list

Conversation

@TMisiukiewicz

@TMisiukiewicz TMisiukiewicz commented May 22, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Problem
On heavy money-request reports the RHP list was effectively non-virtualised. The inner transactions section was rendered via plain .map() inside the parent FlatList's ListHeaderComponent, which renders eagerly. Every transaction row mounted synchronously when the report opened, pushing report open time to ~20–30s for a report with 1600 expenses and producing a noticeable jank window on every navigation.

Solution

  1. Unified list — merged the inner transactions section and the outer report-actions section into a single virtualised list. A discriminated-union UnifiedListItem (section-header | transaction | transactions-footer | report-action) flows through one renderItem dispatcher, so transactions and chat messages now share the same recycler window instead of one being eagerly rendered inside the other's header.

  2. FlashList — migrated the list from react-native's FlatList (FlatListWithScrollKey). initialScrollIndex replaces the FlatList-specific useFlatListScrollKey wrapper

  3. Controller + sub-componentMoneyRequestReportTransactionList continues to own the transaction-domain state (sort, group-by, selection, columns, totals, etc.) and exposes it to the parent via a render-prop controller. The parent renders a small MoneyRequestReportUnifiedList sub-component that assembles the FlashList from controller data plus the report-actions list

Performance numbers (web):
1.6k transactions: 15s -> 660ms
32 transactions: 460ms -> 400ms
128 transactions: 1.6s -> 431ms
192 transactions: 2.3s -> 481ms

Fixed Issues

$ #91425
PROPOSAL:

Tests

Before testing: npm run i-standalone as this PR contains patch to the FlashList

  1. Go to Spend tab
  2. Go to Reports tab
  3. Open Report with a couple of expenses - where list is not scrollable
  4. Verify everything is displayed correctly
  5. Open Report with a lot of expenses in multiple categories
  6. Verify report opens correctly
  7. Select a single report and verify it selects correctly
  8. Select all reports from a category using category header and verify they are all selected (even if they are out of the viewport)
  9. Select all reports from all categories using top table header and verify all reports in a list get selected
  10. Send a message on the report and verify you are scrolled to the bottom of the list
  11. Web only: Narrow down the viewport horizontally and verify the table is scrollable horizontally
  12. Send a couple of messages on the chat
  13. Verify that messages are not scrolled horizontally together with the table
  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
ios.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mov

@codecov

codecov Bot commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/CONST/index.ts 94.81% <ø> (ø)
...ansactionItemRow/DeferredTransactionItemRowRBR.tsx 100.00% <100.00%> (ø)
...ents/TransactionItemRow/TransactionItemRowWide.tsx 99.13% <100.00%> (+<0.01%) ⬆️
src/components/TransactionItemRow/index.tsx 83.60% <100.00%> (+0.55%) ⬆️
src/hooks/useReportActionsScroll.ts 98.23% <100.00%> (ø)
src/hooks/useScrollToEndOnNewMessageReceived.ts 94.11% <100.00%> (ø)
src/styles/variables.ts 100.00% <ø> (ø)
...ts/TransactionItemRow/TransactionItemRowNarrow.tsx 0.00% <0.00%> (ø)
...stReportView/MoneyRequestReportTransactionItem.tsx 0.00% <0.00%> (ø)
...ew/MoneyRequestReportTransactionLongPressModal.tsx 0.00% <0.00%> (ø)
... and 4 more
... and 13 files with indirect coverage changes

@TMisiukiewicz TMisiukiewicz changed the title perf: virtualise transaction list in report screen perf: Migrate to Flashlist in MoneyRequestReportTransactionList May 26, 2026
@TMisiukiewicz
TMisiukiewicz marked this pull request as ready for review May 26, 2026 07:20
@TMisiukiewicz
TMisiukiewicz requested review from a team as code owners May 26, 2026 07:20
@melvin-bot
melvin-bot Bot requested review from aimane-chnaif and joekaufmanexpensify and removed request for a team and joekaufmanexpensify May 26, 2026 07:20
@melvin-bot

melvin-bot Bot commented May 26, 2026

Copy link
Copy Markdown

@aimane-chnaif Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

Comment thread src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx Outdated
Comment thread src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6b5c9bef51

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx Outdated
@TMisiukiewicz
TMisiukiewicz force-pushed the perf/virtualised-report-list branch from 5c17a83 to a71286a Compare July 15, 2026 12:40
@TMisiukiewicz

Copy link
Copy Markdown
Contributor Author

@aimane-chnaif addressed all valid comments 🙏

@TMisiukiewicz

Copy link
Copy Markdown
Contributor Author

@aimane-chnaif resolved conflicts, ready for final review

@github-actions

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

This comment has been minimized.

Comment thread patches/@shopify/flash-list/details.md Outdated
Comment thread patches/@shopify/flash-list/details.md Outdated
@TMisiukiewicz
TMisiukiewicz force-pushed the perf/virtualised-report-list branch from 570b3af to 8807db4 Compare July 22, 2026 13:21

@aimane-chnaif aimane-chnaif left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did regression tests as much as I could.
We'll see what bugs QA team will find in staging.

@aimane-chnaif

Copy link
Copy Markdown
Contributor

I think this was mentioned earlier but empty view briefly shows when fast scroll. Let's not block on this.

Screen.Recording.2026-07-22.at.4.17.32.pm.mov
Screenshot 2026-07-22 at 4 18 52 pm

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8807db4866

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

case 'transactions-footer':
return controller.afterListContent;
case 'report-action':
return renderReportAction(item.action, index - reportActionIndexOffset);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Pass raw list indices to edit-mode scroll

When transactions are inlined ahead of chat actions, this subtracts reportActionIndexOffset before the action reaches ReportActionIndexContext. That context is used by ReportActionItemMessageEdit to call reportScrollManager.scrollToIndex(index) on mobile Chrome when the edit composer focuses, so in a money-request report with inline transactions the scroll target becomes a transaction row (or another earlier item) instead of the edited comment. Keep a separate local action index for grouping, but provide the raw FlashList index to context consumers that scroll the unified list.

Useful? React with 👍 / 👎.

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Regression-focused review of the FlashList migration. This is a large, high-leverage change (unified virtualized list + two patches to the shared @shopify/flash-list), so I focused on blast radius outside the money-request report itself. Summary: the transaction-list refactor looks internally consistent and the shared component/deletion surface is safe, but patch +015 touches every list in the app and there is a platform test-evidence gap — those are the two things to nail before merge.

🔴 Highest risk — the +015+mvcp-header-aware FlashList patch touches shared code

patches/@shopify/flash-list/@shopify+flash-list+2.3.0+015+mvcp-header-aware.patch modifies RecyclerView's offset-correction and adds a header onLayout. Because it patches node_modules, it applies to every FlashList in the app, not just this report.

What I verified (✅ = safe):

  • The main inverted chat list is unaffected. Patch +004 forces firstItemOffset = 0 for inverted lists, which makes all three changes no-ops: the diff reduces to layoutDiff (identical to before), the drop-anchor condition offset < firstItemOffset becomes offset < 0 (never true), and the header onLayout is explicitly if (inverted) return.
  • Non-inverted lists without maintainVisibleContentPosition skip the corrected block — it's gated on shouldMaintainVisibleContentPosition().

⚠️ What still needs QA attention:

  1. BaseSelectionList is in the blast radius. BaseSelectionList.tsx:525 is non-inverted, has a ListHeaderComponent, and enables MVCP by default (disableMaintainingScrollPosition = false). SelectionList backs a huge number of screens, so the changed offset-correction math now runs there too. Please explicitly regression-test selection-list-heavy flows (search filters, member/category pickers, any RHP selection list) for scroll-position jumps.
  2. The new header onLayout is NOT MVCP-gated — it fires recyclerViewContext.layout() for every non-inverted list with a ListHeaderComponent (not just MVCP ones). It's guarded by areDimensionsNotEqual, so sub-pixel jitter is suppressed, but a header whose height genuinely oscillates between two values would keep re-triggering layout. Low probability, but it widens the touch surface — worth a smoke test that no headered FlashList thrashes/loops.

(+014+external-window-size is additive and byte-identical when the new prop is unset — ✅ no concern there.)

🟠 Platform test-evidence gap

The checklist marks all 5 platforms as passing, but the Screenshots section only contains iOS Native + macOS web videos — Android Native, Android mWeb, and iOS mWeb are empty. For a virtualization/scroll rewrite, those are exactly the highest-regression-risk platforms (Android's rotate: 180deg inversion path, mWeb momentum scrolling, and the touch behavior of the new horizontal table). Please attach recordings for the missing platforms, specifically covering:

  • Scroll-to-bottom on sending a message (test step 10)
  • Select-all across the viewport (steps 8–9)
  • Deep-link into a report action on a large report (the initialScrollIndex + re-anchor path)
  • The horizontal-table mode (steps 11–13) on Android + mWeb

🟡 Novel horizontal "external scroll" table — verify by hand

ExternalScrollFlashListTable.tsx is the most novel piece: a nested FlashList fed a non-scrolling driver + synthetic scroll events, windowed via the patched overrideWindowSize. It reads clean, but it's inherently fragile and can't be verified statically. Please confirm on-device:

  • Layout flip between inline and horizontal mode (resize the window across the minTableWidth > windowWidth boundary) — scrollOffsetStore, tableOffsetTop, and viewportHeight should re-seed without leaving the table blank or mis-windowed.
  • Scroll-to-new-transaction in horizontal mode — it relies on getRowPageOffset reading layout for a possibly-unmounted row (MoneyRequestReportUnifiedList.tsx:271-283).
  • The try/catch that swallows synthetic-scroll errors during teardown (ExternalScrollFlashListTable.tsx:105-115) is a reasonable guard, but confirm it isn't masking a real error in the common case.

✅ Verified safe (no action needed)

Shared TransactionItemRow changes, deleted files, and the viewable-items index math all check out
  • Shared TransactionItemRow is backward compatible. The new props (shouldSkipDeferRBR, shouldDeferRBR, shouldDefer) are all optional and default to the old behavior (shouldDefer = true reproduces the prior useDeferredValue path byte-for-byte). None of the ~12 other consumers (Search lists, UnreportedExpenseListItem, DuplicateTransactionItem, MergeTransactionItem, RecentlyAddedRow, stories) pass these props, so they're unchanged. RBR still renders for them; only opt-in FlashList rows render RBR immediately.
  • Deleted files have no external consumers. FlatListWithScrollKey, useFlatListScrollKey, getInitialPaginationSize, and getInitialNumReportActionsToRender were only used by this report view — grep confirms nothing else references them.
  • The onViewableItemsChanged index shift is correct. onViewableItemsChangedAdjusted remaps only viewableItems (not changed), which is fine because useReportUnreadMessageScrollTracking consumes only viewableItems. The negative adjusted indices produced by inlined transaction rows are harmless: the non-inverted unread comparison uses maxIndex (dominated by real report actions ≥ 0), and actionBadgeTargetIndex (the minIndex path) isn't supplied by this list.

Minor

  • MoneyRequestReportUnifiedList.tsx:127-128: reportActionItems and data are rebuilt on every render (no useMemo), relying on React Compiler to memoize. Worth confirming this file passes react-compiler-compliance-check so the FlashList data prop identity isn't churning on unrelated re-renders.
  • In horizontal mode with zero visible report actions, all content lives in ListHeaderComponent and FlashList data is []. Confirm the header still renders (transactions visible) rather than the empty branch swallowing it.

Nothing here is a confirmed blocker in the diff itself — the transaction-list logic is sound. The residual risk is concentrated in the shared FlashList patch and untested platforms, so I'd gate merge on SelectionList regression testing + the missing platform recordings.

mountiny
mountiny previously approved these changes Jul 23, 2026

- Reason: Adds an **`overrideWindowSize`** prop that lets a list declare its visible window (`{width, height}`) instead of deriving it from `measureParentSize(internalViewRef)`. Needed for an *externally-driven* list — one whose `renderScrollComponent` is a non-scrolling `View` that grows to the full content height and receives synthetic scroll events from a parent scroller. Without this, FlashList measures the outer container (as tall as all content) as its viewport and renders every row, defeating virtualization. The change is minimal: `measureParentSize` is still assigned to `outerViewSize` and used for `containerViewSizeRef` (layout-change detection) and the 0×0 hidden-guard from patch 002; only the `windowSize` fed to `updateLayoutParams` is `overrideWindowSize ?? outerViewSize`. Fully backward compatible — when the prop is unset, `windowSize === outerViewSize` and behavior is byte-identical. Used by `MoneyRequestReportView`'s horizontally-scrollable transaction table (`ExternalScrollFlashListTable`), which windows its rows against the unified list's vertical scroll.
- Files changed: `src/FlashListProps.ts`, `src/recyclerview/RecyclerView.tsx`, `dist/FlashListProps.d.ts`, `dist/recyclerview/RecyclerView.js`.
- Upstream PR/issue: TBD

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we really need this patch, lets create upstream issue as well. For both

@mountiny
mountiny merged commit fb824ba into Expensify:main Jul 24, 2026
43 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants